#!/bin/bash

DOX_CNF="/root/scripts/update/Doxyfile_m11y"

function log_msg(){
  LOG_FILE="/var/log/`basename $0`.`hostname`.log"
  CONTENT="$1"
  TYPE="$2"

  echo "["`date +"%Y/%m/%d %H:%M:%S"`"]: ""$CONTENT" >> $LOG_FILE
  #[ "$TYPE" == "2" ] && echo "$CONTENT"
  return 0
}

function doxygen_build()
{
  SRCD="$1"
  TGTD="$2"
  PJN="$3"

  rm -rf "$TGTD"
  mkdir "$TGTD"

  log_msg "Generating \"$PJN\" documents to $TGTD"

  cat "$DOX_CNF" | awk 'BEGIN{\
    PJN="'"$PJN"'";\
    SRCD="'"$SRCD"'";\
    TGTD="'"$TGTD"'";\
  }{\
    if ($1 == "PROJECT_NAME") {\
      print "PROJECT_NAME           = \""PJN"\"";\
    } else if ( $1 == "OUTPUT_DIRECTORY" ) {\
      print "OUTPUT_DIRECTORY       = \""TGTD"\"";\
    } else if ( $1 == "INPUT" ) {\
      print "INPUT                  = \""SRCD"\"";\
    } else {\
      print $0;\
    }\
  }' > "$TGTD/Doxyfile"

  log_msg "Doxygen configure done, runing doxygen in \"$TGTD\" ......"

  cur_dir="`pwd`"
  cd "$TGTD"
  doxygen >/dev/null 2>&1
  cd "$cur_dir"

  log_msg "OK! New document generated in \"$TGTD\"!"
  return 0
}

doxygen_build "/pbfd/manageability/ezbmc" \
              "/pbfd/manageability/doxygen/ezbmc" \
              "EZBMC"
doxygen_build "/pbfd/manageability/ezpci" \
              "/pbfd/manageability/doxygen/ezpci" \
              "EZPCI"
doxygen_build "/pbfd/manageability/hpmgmtbase" \
              "/pbfd/manageability/doxygen/hpmgmtbase" \
              "HP Mission Critical Management Base"
doxygen_build "/pbfd/manageability/smx/smx_trunk" \
              "/pbfd/manageability/doxygen/hpsmx" \
              "HP Mission Critical WBEM Providers"
log_msg ""


